package router

import (
	"net/http"
	"xiaoshuo/config"
	"xiaoshuo/controllers"
	"xiaoshuo/pkg/logger"

	"github.com/gin-contrib/sessions"
	session_redis "github.com/gin-contrib/sessions/redis"
	"github.com/gin-gonic/gin"
)

func Router() *gin.Engine {
	r := gin.Default()

	r.Use(gin.LoggerWithConfig((logger.LoggerToFile())))
	r.Use(logger.Recover)
	store, _ := session_redis.NewStore(10, "tcp", config.RedisAddress, "", []byte("secret"))
	r.Use(sessions.Sessions("mysession", store))

	test := r.Group("/test")
	{
		test.GET("/a1/:id", controllers.TestController{}.Test1)
		test.GET("/a", func(ctx *gin.Context) {
			ctx.String(http.StatusOK, "hell test")
		})
	}

	article := r.Group("/article")
	{
		article.GET("/list", controllers.ArticleController{}.GetList)
		article.GET("/info/:id", controllers.ArticleController{}.GetInfo)
		article.POST("/add", controllers.ArticleController{}.AddInfo)
	}

	xiaohua := r.Group("/xiaohua")
	{
		xiaohua.POST("/add", controllers.XiaoHuaController{}.AddXiaoHua)
		xiaohua.POST("/update", controllers.XiaoHuaController{}.UpdateXiaoHua)
		xiaohua.POST("/delete", controllers.XiaoHuaController{}.DeleteXiaoHua)
		xiaohua.GET("/list", controllers.XiaoHuaController{}.GetxiaoHuaList)
	}

	user := r.Group("/user")
	{
		user.POST("/register", controllers.UserController{}.Register)
		user.POST("/login", controllers.UserController{}.Login)
	}

	player := r.Group("/player")
	{
		player.POST("/list", controllers.PlayerController{}.GetPlayers)

	}

	r.POST("/ranking", controllers.PlayerController{}.GetRanking)

	vote := r.Group("/vote")
	{
		vote.POST("/add", controllers.VoteController{}.AddVote)
	}

	return r
}
